//
//  HJMineAccountController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/25.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJMineAccountController.h"
#import "HJMineAccountHeader.h"
#import "HJWithdrawalController.h"
#import "HJWithdrawalRecordController.h"

@interface HJMineAccountController ()
@property(nonatomic,strong)NSArray * titleArr;
@property(nonatomic,strong)NSArray * imageArr;
@property(nonatomic,strong)HJUserModel * userModel;
@property(nonatomic,strong)HJMineAccountHeader *header;
@property(nonatomic,strong)NSString * money;
@end

@implementation HJMineAccountController

-(NSArray *)titleArr {
    if (!_titleArr) {
        _titleArr = @[@"提现",@"提现记录",@"交易明细"];
    }
    return _titleArr;
}
-(NSArray *)imageArr {
    if (!_imageArr) {
        _imageArr = @[@"30",@"29",@"31"];
    }
    return _imageArr;
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadWork];
}
- (void)viewDidLoad {
    [super viewDidLoad];
}
-(void)configTableView {
    self.needHeaderRefresh = YES;
    self.tableViewStyle = UITableViewStylePlain;
    [super configTableView];
    self.tableView.tableHeaderView = [self configHeader];
}
-(void)loadWork {
    [TZHttpTool post:InfoAPI params:nil success:^(NSDictionary *result) {
        self.userModel = [[HJUserModel alloc]init];
        self.userModel = [HJUserModel mj_objectWithKeyValues:result[@"data"]];
        self.header.model = self.userModel;
        self.money = self.userModel.money;
        [self.tableView reloadData];
    } failure:^(NSString *msg) {
        [self showErrorHUDWithError:msg];
    }];
}
-(UIView *)configHeader {
    self.header = [[HJMineAccountHeader alloc]initWithFrame:CGRectMake(0, 0, mScreenWidth, 189)];
    return self.header;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (self.titleArr) {
        cell.textLabel.font = HJFontSize(15);
        cell.textLabel.text = self.titleArr[indexPath.row];
    }
    if (self.imageArr) {
        cell.imageView.image = HJImage(self.imageArr[indexPath.row]);
    }
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(15, 79, mScreenWidth-30, 1.2)];
    line.backgroundColor = HJColorRGB(0);
    line.alpha = 0.05;
    [cell.contentView addSubview:line];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        HJWithdrawalController *withdrawalVC = [[HJWithdrawalController alloc] init];
        withdrawalVC.navTitle = @"提现";
        withdrawalVC.money = self.money;
        [self.navigationController pushViewController:withdrawalVC animated:YES];
    }else if (indexPath.row ==1) {
        [self pushWithdrawalAndTransactionType:withdrawalType navTitle:@"提现记录"];
    }else {
        [self pushWithdrawalAndTransactionType:transactionType navTitle:@"交易明细"];
    }
}

-(void)pushWithdrawalAndTransactionType:(withdrawalWithTransactionType)type navTitle:(NSString *)navTitle {
    HJWithdrawalRecordController *recordVC = [[HJWithdrawalRecordController alloc]init];
    recordVC.navTitle = navTitle;
    recordVC.type = type;
    [self.navigationController pushViewController:recordVC animated:YES];
}

@end
